package com.ga01.controller;

import com.ga01.entity.Student;
import com.ga01.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping
    public List<Student> getAllStudents() {
        return studentService.list();
    }

    @GetMapping("/{id}")
    public Student getStudentById(@PathVariable Integer id) {
        return studentService.getById(id);
    }

    @PostMapping
    public boolean addStudent(@RequestBody Student student) {
        return studentService.save(student);
    }

    @PutMapping
    public boolean updateStudent(@RequestBody Student student) {
        return studentService.updateById(student);
    }

    @DeleteMapping("/{id}")
    public boolean deleteStudent(@PathVariable Integer id) {
        return studentService.removeById(id);
    }
}